package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQuery;
import cn.wolfcode.luowowo.query.RegionQueryObject;
import cn.wolfcode.luowowo.service.IDestinationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Autowired
    private IDestinationService destinationService;
    //获取所有数据并共享给页面
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page",page);
        return "/destination/list";
    }
    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object updateInfo(Destination destination){
        //先通过id获取到当前传过来的对象
        Destination dest = destinationService.select(destination.getId());
        //再将查询到的对象中的info修改为传过来的对象的info
        dest.setInfo(destination.getInfo());
        //再执行修改操作
        destinationService.updateInfo(dest);
        return JsonResult.success();
    }
}
